package com.lcj;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @author lcj
 */
@Slf4j
@SpringBootApplication
@EnableDiscoveryClient
public class EventListenerApplication {

    public static void main(String[] args) throws UnknownHostException {
        System.setProperty("nacos.logging.default.config.enabled","false");
        // 日志输出使用异步处理，减小输出日志对性能的影响
        // 修改启动类 或 java -jar -DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector xxx.jar
        System.setProperty("Log4jContextSelector", "org.apache.logging.log4j.core.async.AsyncLoggerContextSelector");
        ConfigurableApplicationContext application = SpringApplication.run(EventListenerApplication.class, args);
        Environment env = application.getEnvironment();
        String serverPort = env.getProperty("server.port");
        log.info("""
                        \n----------------------------------------------------------
                        Application '{}' is running! Access URLs:
                        Local: http://localhost:{}
                        External: http://{}:{}
                        Doc: http://{}:{}/doc.html
                        ----------------------------------------------------------
                        """, env.getProperty("spring.application.name"),
                serverPort,
                InetAddress.getLocalHost().getHostAddress(),
                serverPort,
                InetAddress.getLocalHost().getHostAddress(),
                serverPort);
    }
}
